#include("/include/pageForm.html",action="admin/account/search")
<div class="pageHeader">
	<form rel="pagerForm" onsubmit="return navTabSearch(this);" action="admin/account/search" method="post">
	<div class="searchBar">
		<ul class="searchContent">
			<li>
				<label>渠道编号：</label>
				<input type="text" name=channelNo value="#(channelNo)"/>
			</li>
			<li>
				<label>账号：</label>
				<input type="text" name=accountNo value="#(accountNo)"/>
			</li>
		</ul>
		<div class="subBar">
			<ul>
				<li><button onclick="clearhkAmount('hk')"><span>清上游HK商户余额</span></button></li>
				<li><button onclick="clearhkAmount('my')"><span>清系统商户余额</span></button></li>
				<br>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">检索</button></div></div></li>
			</ul>
		</div>
	</div>
	</form>
</div>

<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			#auth()
				<li><a class="add" href="admin/account/addPage" target="dialog" rel="addAccountDialog"  width="600" height="400"><span>添加</span></a></li>
			#end
			#auth()
				<li><a class="edit" href="admin/account/changeEnable?id={sid}" target="ajaxTodo"><span>启用/禁用</span></a></li>
			#end
			#auth()
				<li><a class="edit" href="admin/account/clearD0Amount?id={sid}" target="ajaxTodo"><span>清D0余额</span></a></li>
			#end
		</ul>
	</div>

	<div id="w_list_print">
	<table class="list" style="width: 98%" targetType="navTab" asc="asc" desc="desc" layoutH="136">
		<thead>
			<tr>
				<th width="80">渠道编号</th>
				<th width="100">账号</th>
				<th width="100">名称</th>
				<th width="100">总余额(元)</th>
				<th width="100">可提现余额(元)</th>
				<th width="100">T1提现余额(元)</th>
				<th width="100">状态</th>
				<th width="50">操作</th>
			</tr>
		</thead>
		<tbody>
			#for(item:items)
				<tr target="sid" rel="#(item.id)">
					<td>#(item.channelName)(#(item.channelNo ))</td>
					<td>#(item.accountNo )</td>
					<td>#(item.accountName )</td>
					<td>#number(item.balance.toDouble() / 100,"##,###,##0.00")</td>
					<td>#number((item.balance-item.d0Balance).toDouble() / 100,"##,###,##0.00")</td>
					<td>#number(item.d0Balance.toDouble() / 100,"##,###,##0.00")</td>
					<td>
						#if(item.enable)启用#end
                        #if(item.enable == false)禁用#end
					</td>
					
					<td>
					<button onclick="changeHkAccount('#(item.accountNo )')">调整金额</button>
					</td>
				</tr>
			#end
		</tbody>
	</table>
	</div>
	
	<script type="text/javascript">
		function changeHkAccount(accounNo){
			var comfii = "确定要调整" + accounNo + "虚账余额吗?";
			alertMsg.confirm(comfii, {
				 okCall: function(){
				 		var amt = prompt("请输入需要清除的金额(分为单位，正整数数字, 1元=100分)");
				 		var amt1 = prompt("请再次输入需要清除的金额(分为单位，正整数数字1元=100分)");
				 		
				 		if(amt === amt1){
				 			
				 		}else{
				 			alertMsg.info("两次输入的金额不一致!!");
				 			return;
				 		}
				 		
				 		var passwpord = prompt("请输入虚账清除密码");
				 		
				 		var comgg="确定开始调整虚账:" + accounNo +"需要减掉的金额是 " + amt +"分?";
				 		
				 		
				 		alertMsg.confirm(comgg, {
				 			 okCall: function(){
				 		//发起调转操作
				 		var sdata = "amt=" + amt + "&password=" + passwpord + "&accountNo=" + accounNo;
				 		 $.ajax({
            				type: "POST",
            				url: "admin/account/changeAccount",
            				data: sdata,
            				dataType: "text",
            				success: function(data){
            					alertMsg.info((data));
				 			}
				 		 });
				 		}, cancelCall : function() {}
				 		});
				 	
				 },
				 cancelCall : function() {}
		});
	}
		
		
		
		function  status(startTime,  endTime){
			var d = new Date();
			var date = new Date();
			
			var s = startTime.split(":");
			var e = endTime.split(":");
			 
			
			return date.setHours(s[0],s[1]) < date.setHours(d.getHours(), d.getMinutes()) && date.setHours(d.getHours(), d.getMinutes()) < date.setHours(e[0],e[1]); 
			
		}
		
		function clearhkAmount(cctype){
			if(status('08:59', '21:25')){
				alert('交易时间段,不能进行批量虚账操作!');
				return;
			}
			
			var comfii = "当前时间:" + new Date()   + " 确定要清除所有上游虚账余额吗?";
			alertMsg.confirm(comfii, {
				 okCall: function(){
					 var passwpord = prompt(  "当前时间:" + new Date()   +  "请输入虚账清除密码");
					 if('hk' === cctype){
					 	toclearhkAmount(passwpord);
					 }else{
						 toclearmyAmount(passwpord);
					 }
				 },
				 cancelCall : function() {}
			});
		}
		
		function toclearhkAmount(passwd){
			//发起调转操作
	 		var sdata =  "password=" + passwd ;
	 		 $.ajax({
				type: "POST",
				url: "admin/account/clearhkAmount",
				data: sdata,
				dataType: "text",
				success: function(data){
					alert((data));
	 			}
	 		 });
		}
		
		function toclearmyAmount(passwd){
			//发起调转操作
	 		var sdata =  "password=" + passwd ;
	 		 $.ajax({
				type: "POST",
				url: "admin/account/clearmyAmount",
				data: sdata,
				dataType: "text",
				success: function(data){
					alert((data));
	 			}
	 		 });
		}
		
	</script>
	
	
	
	#include("/include/page.html")

</div>
